/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.customer.core.service.processor.partner;

import info.peigen.hotpot.business.customer.core.domain.partner.Partner;
import info.peigen.hotpot.business.customer.core.domain.partner.PartnerTech;
import info.peigen.hotpot.business.customer.core.service.processor.base.AbstractCustomerServiceProcessor;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.component.open.crypt.service.order.OpenCryptGenerateOrder;
import info.peigen.hotpot.component.open.crypt.service.result.OpenCryptGenerateCryptResult;
import org.noear.solon.annotation.Component;


/**
 * <b>(PartnerApplyPermissionProcessor)</b>
 *
 * @author Lihai
 * @version 1.0.0
 * @since 2022/5/26
 */
@Component
public class PartnerApplyTechProcessor extends AbstractCustomerServiceProcessor implements Processor {
    @Override
    public Integer level() {
        return 55;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        Partner                      partner     = (Partner) serviceContext.getDomain();
        OpenCryptGenerateCryptResult cryptResult = openCryptService.genCrypt(OpenCryptGenerateOrder.builder().partnerId(partner.getPartnerId()).build());
        PartnerTech                  tech        = PartnerTech.builder().partnerPublicKeyStr(cryptResult.getInfo().getPublicKeyStr()).partnerPrivateKeyStr(cryptResult.getInfo().getPrivateKeyStr()).build();

        // 开发模式，固定密钥对，方便开发人员调试
        if (profileConfig.isDev()) {
            tech.setPartnerPublicKeyStr(PartnerTech.SELF_PUBLIC_KEY);
            tech.setPartnerPrivateKeyStr(PartnerTech.SELF_PRIVATE_KEY);
        }
        partner.setTech(tech);
    }
}